#include <iostream>
using namespace std;

int count_bottle(int n)
{
    int count = 0;
    while(n > 1)
    {
        count += (n / 3);
        n = n / 3 + (n % 3);
        if(n == 2)
            n += 1;

    }
    return count;
}

int main() {
    int n;
    // cin读取到成功的输入会返回bool类型，输入0会返回true
    while(cin >> n)
    {
        if(n)
            cout << count_bottle(n) << endl;
    }

    // while(scanf("%d", &n))  // scanf读取到一个成功的输入，会返回成功输入的数据个数，所以说输入0会返回1
    // {
    //     cout << count_bottle(n) << endl;
    // }

    return 0;
}
